package com.example.xianji.activity;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.Request.Method;
import com.android.volley.Response.Listener;
import com.android.volley.toolbox.JsonObjectRequest;
import com.example.xianji.Contant;
import com.example.xianji.XJApplication;
import com.example.xianji.R;
import com.example.xianji.bean.YiJi_Class;
import com.example.xianji.constant.Constant;
import com.example.xianji.single.Single;
import com.example.xianji.utils.sp.PreferenceEngine;
/*import com.example.xianji.widgets.CustomProgressDialog;
 */
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.drawable.BitmapDrawable;
import android.text.Html;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

/**
 * 企业编辑信息页面
 *
 * @author me
 */
public class Main_Bianji_QiYe_InformationActivity extends Activity implements OnClickListener {
    private EditText qiye_bianji_edittext_nickname, edittext_qiye_bianji_money, qiye_bianji_edittext_man, edittext_qiye_bianji_email, edittext_qiye_bianji_jianjie, edittext_code, edittext_tel, edittext_ext, qiye_bianji_text_hangey_name;
    private TextView qiye_bianji_textview_guimo, qiye_bianji_textview_phone, textview_qiye_bianji_save;
    private String group[] = new String[]{">100人", "51-100人", "21-50人", "5-20人", "<5人"};
    private LinearLayout layout, linearlayout_qiye_bianji_guimo, linearlayout_hangye;
    private ListView show_listview;
    private PopupWindow show_popupWindow;
    //    private SharedPreferences sp;
//    private Editor ed;
    private int qiye_guimo;
    private ImageView qiye_bianji_xinxi_back;
    private Button qiye_button_privonce, qiye_button_city, qiye_button_distrct, change_phone;
    //private CustomProgressDialog mCustomProgressDialog;
    private ArrayList<YiJi_Class> list;
    private MyAdapter mMyAdapter;
    private int qiye_province_id, qiye_city_id, qiye_distrct_id;
    private boolean qiye_city_flag = false, qiye_distrct_flag = false, qiye_province_flag = false;
    public static int save;
    public static ArrayList<YiJi_Class> yiji_list;
    private ArrayList<YiJi_Class> hangye_list = new ArrayList<YiJi_Class>();
    private Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 1) {
                show_listview.setAdapter(mMyAdapter);
			/*if(mCustomProgressDialog!=null){
					mCustomProgressDialog.dismiss();
					mCustomProgressDialog=null;
				}*/
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main__bianji__qi_ye__information);
        //XJApplication.getInstance().addActivity(this);
        qiye_bianji_edittext_nickname = (EditText) findViewById(R.id.qiye_bianji_edittext_nickname);
        qiye_bianji_text_hangey_name = (EditText) findViewById(R.id.qiye_bianji_text_hangey_name);
        qiye_bianji_textview_guimo = (TextView) findViewById(R.id.qiye_bianji_textview_guimo);
        edittext_qiye_bianji_money = (EditText) findViewById(R.id.edittext_qiye_bianji_money);
        qiye_bianji_edittext_man = (EditText) findViewById(R.id.qiye_bianji_edittext_man);
        edittext_qiye_bianji_email = (EditText) findViewById(R.id.edittext_qiye_bianji_email);
        qiye_bianji_textview_phone = (TextView) findViewById(R.id.qiye_bianji_textview_phone);
        edittext_qiye_bianji_jianjie = (EditText) findViewById(R.id.edittext_qiye_bianji_jianjie);
        linearlayout_qiye_bianji_guimo = (LinearLayout) findViewById(R.id.linearlayout_qiye_bianji_guimo);
//        sp = getSharedPreferences("text", MODE_PRIVATE);
//        ed = sp.edit();
        qiye_button_privonce = (Button) findViewById(R.id.qiye_button_privonce);
        qiye_button_city = (Button) findViewById(R.id.qiye_button_city);
        qiye_button_distrct = (Button) findViewById(R.id.qiye_button_distrct);
        linearlayout_hangye = (LinearLayout) findViewById(R.id.linearlayout_hangye);
        change_phone = (Button) findViewById(R.id.change_phone);
        edittext_code = (EditText) findViewById(R.id.edittext_code);
        edittext_tel = (EditText) findViewById(R.id.edittext_tel);
        edittext_ext = (EditText) findViewById(R.id.edittext_ext);


        textview_qiye_bianji_save = (TextView) findViewById(R.id.textview_qiye_bianji_save);
        qiye_bianji_xinxi_back = (ImageView) findViewById(R.id.qiye_bianji_xinxi_back);
        if (getIntent().getIntExtra("isMobile", 0) == Contant.not_mobile) {
            //没有手机号，从登录完跳转的编辑信息页面
            change_phone.setText("新增手机号");
            get_qiye_information();

        } else {
            //有手机号的，是从后台编辑页面进入的
            yiji_list = Single.getInstance().getList();


            qiye_province_id = getIntent().getIntExtra("qiye_province_id", 0);
            if (getIntent().getStringExtra("qiye_province").equals("上海") || getIntent().getStringExtra("qiye_province").equals("北京") || getIntent().getStringExtra("qiye_province").equals("天津")
                    || getIntent().getStringExtra("qiye_province").equals("香港") || getIntent().getStringExtra("qiye_province").equals("台湾")
                    ) {
                //qiye_city_id=getIntent().getIntExtra("qiye_province_id",0);
            } else {
            }
            qiye_city_id = getIntent().getIntExtra("qiye_city_id", 0);
            qiye_distrct_id = getIntent().getIntExtra("qiye_distrct_id", 0);
            qiye_bianji_edittext_nickname.setText(getIntent().getStringExtra("qiye_name"));
            qiye_bianji_text_hangey_name.setText(getIntent().getStringExtra("qiye_hangye"));
            qiye_bianji_textview_guimo.setText(getIntent().getStringExtra("qiye_guimo"));
            edittext_qiye_bianji_money.setText(getIntent().getStringExtra("qiye_money"));
            qiye_bianji_textview_phone.setText(getIntent().getStringExtra("qiye_mobile"));
            qiye_bianji_edittext_man.setText(getIntent().getStringExtra("qiye_man_name"));
            edittext_qiye_bianji_jianjie.setText(Html.fromHtml(getIntent().getStringExtra("qiye_jianjie")));
            edittext_qiye_bianji_email.setText(getIntent().getStringExtra("qiye_email"));
            qiye_guimo = getIntent().getIntExtra("qiye_guimo_id", 0);
            edittext_code.setText(getIntent().getStringExtra("code"));
            edittext_tel.setText(getIntent().getStringExtra("tel"));
            edittext_ext.setText(getIntent().getStringExtra("ext"));
            qiye_button_privonce.setText(getIntent().getStringExtra("qiye_province"));
            if (getIntent().getStringExtra("qiye_province").length() > 0) {
                qiye_province_flag = true;
                if (getIntent().getStringExtra("qiye_province").equals("上海") || getIntent().getStringExtra("qiye_province").equals("北京") || getIntent().getStringExtra("qiye_province").equals("天津")
                        || getIntent().getStringExtra("qiye_province").equals("香港") || getIntent().getStringExtra("qiye_province").equals("台湾")) {
                    qiye_city_flag = true;
                } else if (getIntent().getStringExtra("qiye_city").length() > 0) {
                    qiye_city_flag = true;
                }
            }

            if (getIntent().getStringExtra("qiye_province").equals("上海") || getIntent().getStringExtra("qiye_province").equals("北京") || getIntent().getStringExtra("qiye_province").equals("天津")
                    || getIntent().getStringExtra("qiye_province").equals("香港") || getIntent().getStringExtra("qiye_province").equals("台湾")) {
                qiye_button_city.setText(getIntent().getStringExtra("qiye_province"));
                qiye_button_distrct.setText(getIntent().getStringExtra("qiye_distrct"));

            } else {
                qiye_button_city.setText(getIntent().getStringExtra("qiye_city"));
                qiye_button_distrct.setText(getIntent().getStringExtra("qiye_distrct"));
            }
        }
        linearlayout_qiye_bianji_guimo.setOnClickListener(this);
        textview_qiye_bianji_save.setOnClickListener(this);
        qiye_bianji_xinxi_back.setOnClickListener(this);
        qiye_button_privonce.setOnClickListener(this);
        qiye_button_city.setOnClickListener(this);
        qiye_button_distrct.setOnClickListener(this);
        //linearlayout_hangye.setOnClickListener(this);
        change_phone.setOnClickListener(this);
    }

    /**
     * 从登录页面跳转到企业编辑页面
     */
    public void get_qiye_information() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("token", getIntent().getStringExtra("xianji_token"));
        JSONObject parmas = new JSONObject(map);
        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.yonghu_infor,
                parmas, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        JSONArray array = response.getJSONArray("data");
                        JSONObject object0 = array.getJSONObject(0);
                        JSONObject object1 = array.getJSONObject(1);
                        JSONObject object2 = array.getJSONObject(2);
                        qiye_bianji_edittext_nickname.setText(object0.getString("nickname"));
							/*if(object2.getJSONArray("boothpcate").length()>1){
								hangye_list.clear();
								JSONArray hangye_array=object2.getJSONArray("boothpcate");
								
								for (int i = 0; i < hangye_array.length(); i++) {
									JSONObject hangye_object=hangye_array.getJSONObject(i);
									YiJi_Class mYiJi_Class=new YiJi_Class();
									
									mYiJi_Class.setId(hangye_object.getInt("parent"));
									mYiJi_Class.setName(hangye_object.getString("parent_name"));
									hangye_list.add(mYiJi_Class);
									yiji_list=hangye_list;
								}
								
								
								Single.getInstance().setList(hangye_list);
								qiye_bianji_text_hangey_name.setText(object2.getJSONArray("boothpcate").getJSONObject(0).getString("parent_name")+"等");
							}else  if(object2.getJSONArray("boothpcate").length()==1){
								qiye_bianji_text_hangey_name.setText(object2.getJSONArray("boothpcate").getJSONObject(0).getString("parent_name"));
							}else{
								qiye_bianji_text_hangey_name.setText("请选择行业");
								
							}*/
                        qiye_bianji_text_hangey_name.setText(object2.getJSONObject("hytags").getString("tag_name"));
                        if (object1.getInt("scope") == 1) {

                            qiye_bianji_textview_guimo.setText(">100人");
                        } else if (object1.getInt("scope") == 2) {

                            qiye_bianji_textview_guimo.setText("51-100人");
                        } else if (object1.getInt("scope") == 3) {

                            qiye_bianji_textview_guimo.setText("21-50人");
                        } else if (object1.getInt("scope") == 4) {

                            qiye_bianji_textview_guimo.setText("5-20人");
                        } else if (object1.getInt("scope") == 5) {

                            qiye_bianji_textview_guimo.setText("<5人");
                        }
                        qiye_guimo = object1.getInt("scope");

                        edittext_qiye_bianji_money.setText(object1.getString("capital"));
                        qiye_bianji_edittext_man.setText(object1.getString("name"));
                        edittext_qiye_bianji_email.setText(object0.getString("email"));
                        qiye_bianji_textview_phone.setText(object0.getString("mobile"));
                        qiye_button_privonce.setText(object1.getString("province_name"));
                        //qiye_textview_place.setText(object1.getString("province_name")+object1.getString("city_name")+object1.getString("district_name"));

                        if (object1.getString("province_name").equals("上海") || object1.getString("province_name").equals("北京") || object1.getString("province_name").equals("天津")
                                || object1.getString("province_name").equals("香港") || object1.getString("province_name").equals("台湾")) {
                            qiye_button_city.setText(object1.getString("province_name"));
                            qiye_city_id = object1.getInt("province");
                            qiye_button_distrct.setText(object1.getString("city_name"));
                            qiye_distrct_id = object1.getInt("city");

                        } else {
                            qiye_button_city.setText(object1.getString("city_name"));
                            qiye_city_id = object1.getInt("city");
                            qiye_button_distrct.setText(object1.getString("district_name"));
                            qiye_distrct_id = object1.getInt("district");
                        }


                        edittext_qiye_bianji_jianjie.setText(Html.fromHtml(object1.getString("info")));
                        qiye_province_id = object1.getInt("province");
							/*if(qiye_province.equals("上海")||qiye_province.equals("北京")||qiye_province.equals("天津")
									||qiye_province.equals("香港")||qiye_province.equals("台湾")){
								qiye_city_id=object1.getInt("city");
								qiye_distrct_id=object1.getInt("district");
								
											}else{
												qiye_city_id=object1.getInt("city");
												qiye_distrct_id=object1.getInt("district");
											}*/

                        edittext_code.setText(object1.getString("code"));
                        edittext_tel.setText(object1.getString("tel"));
                        edittext_ext.setText(object1.getString("ext"));


                    } else {

                        //Toast.makeText(getActivity(),response.getString("msg"),0).show();
                    }
						/*
						if(mCustomProgressDialog!=null){
							mCustomProgressDialog.dismiss();
							
							mCustomProgressDialog=null;
						}*/
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
					/*if(mCustomProgressDialog!=null){
						mCustomProgressDialog.dismiss();
						
						mCustomProgressDialog=null;
					}*/
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();

    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.linearlayout_qiye_bianji_guimo) {
            Photo_show();
            show_popupWindow.showAtLocation(findViewById(R.id.qiye_bianji), Gravity.BOTTOM, 0, 0);
            show_listview.setAdapter(new ArrayAdapter<String>(Main_Bianji_QiYe_InformationActivity.this, R.layout.information_show_photo_item, R.id.show_photo_item_text, group));
            show_listview.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1,
                                        int arg2, long arg3) {
                    qiye_bianji_textview_guimo.setText(group[arg2]);
                    qiye_bianji_textview_guimo.setTextColor(getResources().getColor(R.color.black3F));
                    if (show_popupWindow != null) {

                        show_popupWindow.dismiss();
                        show_popupWindow = null;
                    }

                    if (group[arg2].equals(">100人")) {
                        qiye_guimo = 1;

                    } else if (group[arg2].equals("51-100人")) {

                        qiye_guimo = 2;
                    } else if (group[arg2].equals("21-50人")) {

                        qiye_guimo = 3;
                    } else if (group[arg2].equals("5-20人")) {

                        qiye_guimo = 4;
                    } else if (group[arg2].equals("<5人")) {

                        qiye_guimo = 5;
                    }

                }
            });
        } else if (v.getId() == R.id.textview_qiye_bianji_save) {
            save = 1;
            if (qiye_bianji_textview_phone.getText().toString().length() > 0) {
                save_info();
            } else {
                Toast.makeText(Main_Bianji_QiYe_InformationActivity.this, "手机号必须填写哦", Toast.LENGTH_SHORT).show();
            }
        } else if (v.getId() == R.id.qiye_bianji_xinxi_back) {

            this.finish();
        } else if (v.getId() == R.id.qiye_button_privonce) {

            Photo_show();


            list = new ArrayList<YiJi_Class>();


            show_popupWindow.showAtLocation(findViewById(R.id.qiye_bianji), Gravity.BOTTOM, 0, 0);
		
	/*	mCustomProgressDialog=CustomProgressDialog.createDialog(this);
		mCustomProgressDialog.setCanceledOnTouchOutside(false);
		mCustomProgressDialog.show();*/
            get_province();

            show_listview.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                        long arg3) {
                    qiye_province_id = list.get(arg2).getId();
                    qiye_button_privonce.setText(list.get(arg2).getName());
                    if (show_popupWindow != null) {
                        show_popupWindow.dismiss();
                        show_popupWindow = null;
                    }
                    qiye_province_flag = true;
                    qiye_city_flag = false;
                    qiye_distrct_flag = false;
                    qiye_button_city.setText("城市");
                    qiye_button_distrct.setText("区域");
                }
            });
        } else if (v.getId() == R.id.qiye_button_city) {
            if (qiye_province_flag) {

                Photo_show();
                list = new ArrayList<YiJi_Class>();
		
	
		/*mCustomProgressDialog=CustomProgressDialog.createDialog(this);
		mCustomProgressDialog.setCanceledOnTouchOutside(false);
		mCustomProgressDialog.show();*/
                if (qiye_button_privonce.getText().toString().equals("北京") || qiye_button_privonce.getText().toString().equals("上海") || qiye_button_privonce.getText().toString().equals("天津") ||
                        qiye_button_privonce.getText().toString().equals("香港") || qiye_button_privonce.getText().toString().equals("台湾")
                        ) {

                    get_teshu_province();

                } else {

                    get_city();
                }


                show_popupWindow.showAtLocation(findViewById(R.id.qiye_bianji), Gravity.BOTTOM, 0, 0);

                show_listview.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                            long arg3) {
                        qiye_city_id = list.get(arg2).getId();
                        qiye_button_city.setText(list.get(arg2).getName());
                        if (show_popupWindow != null) {
                            show_popupWindow.dismiss();
                            show_popupWindow = null;
                        }
                        qiye_city_flag = true;
                        qiye_distrct_flag = false;
                        qiye_button_distrct.setText("区域");
                    }
                });

            } else {
                Toast.makeText(Main_Bianji_QiYe_InformationActivity.this, "请先选择省份", Toast.LENGTH_SHORT).show();
            }
        } else if (v.getId() == R.id.qiye_button_distrct) {
            if (qiye_city_flag) {
                list = new ArrayList<YiJi_Class>();
                Photo_show();
		
	/*	mCustomProgressDialog=CustomProgressDialog.createDialog(this);
		mCustomProgressDialog.setCanceledOnTouchOutside(false);
		mCustomProgressDialog.show();*/
                get_district();

                show_popupWindow.showAtLocation(findViewById(R.id.qiye_bianji), Gravity.BOTTOM, 0, 0);

                show_listview.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                            long arg3) {
                        qiye_distrct_id = list.get(arg2).getId();
                        qiye_button_distrct.setText(list.get(arg2).getName());
                        if (show_popupWindow != null) {
                            show_popupWindow.dismiss();
                            show_popupWindow = null;
                        }
                    }
                });
            } else {
                Toast.makeText(Main_Bianji_QiYe_InformationActivity.this, "请先选择城市", Toast.LENGTH_SHORT).show();
            }
        } else if (v.getId() == R.id.change_phone) {
            Intent intent = new Intent(Main_Bianji_QiYe_InformationActivity.this, Main_Regesiter_OneActivity.class);
            if (getIntent().getIntExtra("isMobile", 0) == Contant.not_mobile) {
                //从登录页面跳转到编辑页面是  新增手机号
                intent.putExtra("from", 3);
                intent.putExtra("xianji_token", getIntent().getStringExtra("xianji_token"));
            } else {
                //修改手机号
                intent.putExtra("from", 2);
            }
            startActivity(intent);
        }
    }

    /**
     * 省份请求
     */
    public void get_province() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("pid", 0);
        JSONObject params = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.place,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {

                try {
                    if (response.getInt("status") == 1) {

                        JSONArray array = response.getJSONArray("data");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject obj = array.getJSONObject(i);
                            YiJi_Class mYiJi_Class = new YiJi_Class();
                            mYiJi_Class.setId(obj.getInt("id"));
                            mYiJi_Class.setName(obj.getString("name"));

                            list.add(mYiJi_Class);
                        }

                    } else {
                        Toast.makeText(Main_Bianji_QiYe_InformationActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();
                    }

                    handler.sendEmptyMessage(1);
                } catch (JSONException e) {
                    e.printStackTrace();
                }


            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
  						/*if(mCustomProgressDialog!=null){
  							mCustomProgressDialog.dismiss();
  							mCustomProgressDialog=null;
  						}*/

                if (show_popupWindow != null) {
                    show_popupWindow.dismiss();
                    show_popupWindow = null;

                }
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();

    }

    /**
     * 省份请求
     */
    public void get_teshu_province() {


        YiJi_Class mYiJi_Class = new YiJi_Class();
        mYiJi_Class.setId(qiye_province_id);
        mYiJi_Class.setName(qiye_button_privonce.getText().toString());


        list.add(mYiJi_Class);
        handler.sendEmptyMessage(1);


    }

    /**
     * 地区请求
     */
    public void get_city() {

        HashMap<String, Object> map = new HashMap<String, Object>();


        map.put("pid", qiye_province_id);
        Log.i("进入进入进入", "进入进入进入");

        JSONObject params = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.place,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {

                try {
                    if (response.getInt("status") == 1) {

                        JSONArray array = response.getJSONArray("data");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject obj = array.getJSONObject(i);
                            YiJi_Class mYiJi_Class = new YiJi_Class();
                            mYiJi_Class.setId(obj.getInt("id"));
                            mYiJi_Class.setName(obj.getString("name"));
                            list.add(mYiJi_Class);
                        }

                    } else {
                        Toast.makeText(Main_Bianji_QiYe_InformationActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();
                    }

                    handler.sendEmptyMessage(1);
                } catch (JSONException e) {
                    e.printStackTrace();
                }


            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
	  					/*	if(mCustomProgressDialog!=null){
	  							mCustomProgressDialog.dismiss();
	  							mCustomProgressDialog=null;
	  						}*/

                if (show_popupWindow != null) {
                    show_popupWindow.dismiss();
                    show_popupWindow = null;

                }
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();


    }

    /**
     * 城市请求
     */
    public void get_district() {

        HashMap<String, Object> map = new HashMap<String, Object>();
        if (qiye_button_privonce.getText().toString().equals("北京") || qiye_button_privonce.getText().toString().equals("上海") || qiye_button_privonce.getText().toString().equals("天津") ||
                qiye_button_privonce.getText().toString().equals("香港") || qiye_button_privonce.getText().toString().equals("台湾")) {
            map.put("pid", qiye_province_id);

        } else {
            map.put("pid", qiye_city_id);
        }


        Log.i("进入进入进入", "进入进入进入");

        JSONObject params = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.place,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {

                        JSONArray array = response.getJSONArray("data");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject obj = array.getJSONObject(i);
                            YiJi_Class mYiJi_Class = new YiJi_Class();
                            mYiJi_Class.setId(obj.getInt("id"));
                            mYiJi_Class.setName(obj.getString("name"));
                            list.add(mYiJi_Class);
                        }

                    } else {
                        Toast.makeText(Main_Bianji_QiYe_InformationActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();
                    }

                    handler.sendEmptyMessage(1);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
	  					/*	if(mCustomProgressDialog!=null){ 
	  							mCustomProgressDialog.dismiss();
	  							mCustomProgressDialog=null;
	  						}*/

                if (show_popupWindow != null) {
                    show_popupWindow.dismiss();
                    show_popupWindow = null;

                }
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();


    }

    public void save_info() {
        Log.i("进入今日进入", "进入今日进入");

	/*JSONArray values=new JSONArray();
	for (int i = 0; i < yiji_list.size(); i++) {
		
		values.put(yiji_list.get(i).getId());
	}*/
        HashMap<String, Object> map = new HashMap<String, Object>();
        if (getIntent().getIntExtra("isMobile", 0) == Contant.not_mobile) {
            //从登录页面过来的token
            map.put("token", getIntent().getStringExtra("xianji_token"));
        } else {
            map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
        }
        map.put("nickname", qiye_bianji_edittext_nickname.getText().toString());
        map.put("name", qiye_bianji_edittext_man.getText().toString());
        map.put("email", edittext_qiye_bianji_email.getText().toString());


        map.put("ctags", qiye_bianji_text_hangey_name.getText().toString());

        map.put("mobile", qiye_bianji_textview_phone.getText().toString());

        map.put("scope", qiye_guimo);

        map.put("code", edittext_code.getText().toString());
        map.put("tel", edittext_tel.getText().toString());
        map.put("ext", edittext_ext.getText().toString());
        Log.i("cccccc", qiye_guimo + "");

        map.put("capital", edittext_qiye_bianji_money.getText().toString());


        map.put("info", edittext_qiye_bianji_jianjie.getText().toString());

        map.put("province", qiye_province_id);
        if (qiye_button_privonce.getText().toString().equals("北京") || qiye_button_privonce.getText().toString().equals("上海") || qiye_button_privonce.getText().toString().equals("天津") ||
                qiye_button_privonce.getText().toString().equals("香港") || qiye_button_privonce.getText().toString().equals("台湾")) {
            if (qiye_distrct_id == 0) {
                map.put("city", qiye_city_id);
            } else {
                map.put("city", qiye_distrct_id);
            }
            map.put("district", 0);

        } else {

            map.put("city", qiye_city_id);
            map.put("district", qiye_distrct_id);
        }


        JSONObject parmas = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.save_info,
                parmas, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        Toast.makeText(Main_Bianji_QiYe_InformationActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();
                        //修改成功后，手机号清空
                        Main_Change_phone_numberActivity.Change_Phone = "";
                        if (getIntent().getIntExtra("isMobile", 0) == Contant.not_mobile) {
                            //从登录页面没有手机号跳转到的编辑信息页面
                            PreferenceEngine.getInstance().putBoolean(Constant.SP.NAME, Constant.SP.KEY_XIANJI_DENGLU, true);
//                            ed.putBoolean("xianji_denglu", true);
                            PreferenceEngine.getInstance().putString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, getIntent().getStringExtra("xianji_token"));
//                            ed.putString("xianji_token", getIntent().getStringExtra("xianji_token"));
                            PreferenceEngine.getInstance().putInt(Constant.SP.NAME, Constant.SP.KEY_FINISH_FROM, 2);
//                            ed.putInt("finish_from", 2);
                            PreferenceEngine.getInstance().putInt(Constant.SP.NAME, Constant.SP.KEY_MY_XIANJI_SET, 2);
//                            ed.putInt("my_xianji_set", 2);
//                            ed.commit();
                            //来自于服务详情页面的登录成功赋值为2
                            if (Contant.come_from_fuwuDetail == 1) {
                                Contant.come_from_fuwuDetail = 2;
                            }
                            Contant.login_resume = 1;
                            //如果从登录页面登录成功后则设置为0，如果是点返回键回到"我的后台"则是1，得加载数据
                            Contant.change_password_login = 0;

                        }
                        Main_Bianji_QiYe_InformationActivity.this.finish();
                    } else {

                        Toast.makeText(Main_Bianji_QiYe_InformationActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }


            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    private void Photo_show() {
        layout = (LinearLayout) LayoutInflater.from(
                Main_Bianji_QiYe_InformationActivity.this).inflate(
                R.layout.information_shoow_photo, null);
        show_listview = (ListView) layout.findViewById(R.id.information_photo_listview);

        show_listview.setCacheColorHint(0);
        mMyAdapter = new MyAdapter();
        show_popupWindow = new PopupWindow(layout, WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT);
        show_popupWindow.setBackgroundDrawable(new BitmapDrawable());
        show_popupWindow.setHeight(700);
        show_popupWindow.setAnimationStyle(R.style.mypopwindow_anim_style);
        show_popupWindow.update();
        show_popupWindow.setOutsideTouchable(true);
        show_popupWindow.setFocusable(true);
        show_popupWindow.setContentView(layout);

    }


    class MyAdapter extends BaseAdapter {


        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int arg0) {
            return arg0;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Holder mHolder;
            if (convertView == null) {
                mHolder = new Holder();
                convertView = View.inflate(Main_Bianji_QiYe_InformationActivity.this, R.layout.listview_item_layout, null);
                mHolder.place_text = (TextView) convertView.findViewById(R.id.place_text);
                convertView.setTag(mHolder);
            }
            mHolder = (Holder) convertView.getTag();
            mHolder.place_text.setText(list.get(position).getName());

            return convertView;
        }


    }

    class Holder {
        TextView place_text;


    }

    @Override
    protected void onRestart() {
        super.onRestart();
	/*	if(Main_Choose_HangyeActivity.array.size()>0){
			qiye_bianji_text_hangey_name.setText("已选择"+Main_Choose_HangyeActivity.array.size()+"项");
			Log.i("qqqqqqq",Main_Choose_HangyeActivity.indext.size()+"");
			
			qiye_bianji_text_hangey_name.setTextColor(getResources().getColor(R.color.black));
			
			
			}else{
				
				qiye_bianji_text_hangey_name.setText("请选择从事行业");
				qiye_bianji_text_hangey_name.setTextColor(getResources().getColor(R.color.huise));
			}*/

        if (Main_Change_phone_numberActivity.Change_Phone.length() > 0) {
            //如果修改了手机号，那就把修改的手机号赋值
            qiye_bianji_textview_phone.setText(Main_Change_phone_numberActivity.Change_Phone);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        handler.removeCallbacksAndMessages(null);
    }
}
